import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import { resolve } from 'path';
import dts from 'vite-plugin-dts';
export default defineConfig({
  build: {
    target: 'modules',
    outDir: 'kunkun-ui',
    //压缩
    minify: false,
    //css分离
    // cssCodeSplit: true,
    lib: {
      // Could also be a dictionary or array of multiple entry points
      entry: resolve(__dirname, 'src/index.ts'),
      name: 'kunkun-ui',
    },
    rollupOptions: {
      // 确保外部化处理那些你不想打包进库的依赖
      external: ['vue'],
      input: ['src/index.ts'],
      output: [
        {
          format: 'es',
          //不用打包成.es.js,这里我们想把它打包成.js
          entryFileNames: '[name].js',
          //让打包目录和我们目录对应
          preserveModules: true,
          //配置打包根目录
          dir: 'kunkun-ui-es',
          preserveModulesRoot: 'src',
        },
        {
          format: 'cjs',
          entryFileNames: '[name].js',
          //让打包目录和我们目录对应
          preserveModules: true,
          //配置打包根目录
          dir: 'kunkun-ui-cjs',
          preserveModulesRoot: 'src',
        },
      ],
    },
  },
  plugins: [
    vue(),
    dts({
      outDir: 'kunkun-ui-es',
      tsconfigPath: './tsconfig.json',
    }),
    dts({
      outDir: 'kunkun-ui-cjs',
      tsconfigPath: './tsconfig.json',
    }),
  ],
});
